<?php 
	if($users != NULL){
	
	$role = $this->session->userdata('role');
	
	$tk1 		= $users[0]['TK1'];
	$tk2 		= $users[0]['TK2'];
	$tk3 		= $users[0]['TK3'];
	
	$alamat_tk1	= $users[0]['ALAMAT_TK1'];
	$alamat_tk2	= $users[0]['ALAMAT_TK2'];
	$alamat_tk3	= $users[0]['ALAMAT_TK3'];
	
	$lembar_tk1	= $users[0]['LEMBAR_TK1'];
	$lembar_tk2	= $users[0]['LEMBAR_TK2'];
	$lembar_tk3	= $users[0]['LEMBAR_TK3'];
	
	if($this->session->userdata('role') == 6)
	{
		if($users[0]['STATUS_TK1'] == 'NF')
		{
			$tk1		= NULL;
			$alamat_tk1	= NULL;
			$lembar_tk1	= NULL;
		}
		
		if($users[0]['STATUS_TK2'] == 'NF')
		{
			$tk2		= NULL;
			$alamat_tk2	= NULL;
			$lembar_tk2	= NULL;
		}
		
		if($users[0]['STATUS_TK3'] == 'NF')
		{
			$tk3		= NULL;
			$alamat_tk3	= NULL;
			$lembar_tk3	= NULL;
		}
		
		
	}
	elseif($this->session->userdata('role') == 7)
	{
		if($users[0]['STATUS_TK1'] != 'NF')
		{
			$tk1		= NULL;
			$alamat_tk1	= NULL;
			$lembar_tk1	= NULL;
		}
		
		if($users[0]['STATUS_TK2'] != 'NF')
		{
			$tk2		= NULL;
			$alamat_tk2	= NULL;
			$lembar_tk2	= NULL;
		}
		
		if($users[0]['STATUS_TK3'] != 'NF')
		{
			$tk3		= NULL;
			$alamat_tk3	= NULL;
			$lembar_tk3	= NULL;
		}
	}
	
?>
<style>
	.loader{
		position:fixed;
		top:0;
		left:0;
		background:rgba(255,255,255,0.8) url('<?php echo base_url("images/loading.gif");?>') no-repeat 50%;
		height:100%;
		width:100%;
		z-index:900;
		overflow:hidden;
	}
</style>
<div class="row">
	<div class="col-sm-6">
		<section class="panel">
			<header class="bg-info panel-heading font-bold" style="background-color:#6c0a00">Biodata</header>
			<div class="panel-body">
				<form class="form-horizontal" method="get">
					<div class="form-group">
						<label class="col-sm-4 control-label">Nama lengkap</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" data-required="true" value="<?php echo $users[0]['NAMA_LENGKAP']; ?>" disabled>
						</div>
					</div>
					<div class="line line-dashed line-lg pull-in"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label">Tempat lahir</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" data-required="true" value="<?php echo $users[0]['TEMPAT_LAHIR']; ?>" disabled>
					</div>
					</div>
					<div class="line line-dashed line-lg pull-in"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label">Tanggal lahir</label>
						<div class="col-sm-7">
							<input class="datepicker-input form-control" data-required="true" type="text" data-date-format="dd-mm-yyyy" value="<?php $date = explode('-', $users[0]['TGL_LAHIR']); echo $date[2].'-'.$date[1].'-'.$date[0]; ?>" disabled>
						</div>
					</div>
					<div class="line line-dashed line-lg pull-in"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label">Jenis kelamin</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" data-required="true" value="<?php if($users[0]['JENIS_KELAMIN'] == 1) echo 'Laki-laki'; else echo 'Perempuan';?>" disabled>
						</div>
					</div>
					<div class="line line-dashed line-lg pull-in"></div>
						<div class="form-group">
						<label class="col-sm-4 control-label">Alamat</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" data-required="true" value="<?php echo $users[0]['ALAMAT']; ?>" disabled>
						</div>
					</div>
					<div class="line line-dashed line-lg pull-in"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label">Nomor telepon</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" data-required="true" value="<?php echo $users[0]['TELP']; ?>" disabled>
						</div>
					</div>
					<div class="line line-dashed line-lg pull-in"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label">Nomor handphone</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" data-required="true" value="<?php echo $users[0]['HP']; ?>" disabled>
						</div>
					</div>
					<div class="line line-dashed line-lg pull-in"></div>
					<div class="form-group">
						<div class="col-sm-11 control-label">
							<a class="btn btn-info" target="_blank" href="<?php echo base_url().$users[0]['ALAMAT_KTP'];?>"><i class="fa fa-file text"></i><span class="text"> KTP</span></a>
						</div>
					</div>					
				</form>
			</div>
		</section>	
	</div>
	<div class="col-sm-6">
		<section class="panel">
			<header class="bg-info panel-heading font-bold" style="background-color:#6c0a00">Permohonan Legalisir</header>
			<div class="panel-body">
				<form class="form-horizontal" method="get">
					<div class="form-group">
						<label class="col-sm-4 control-label">Tanggal permohonan</label>
						<div class="col-sm-7">
							<input class="form-control" data-required="true" type="text" data-date-format="dd-mm-yyyy" value="<?php echo $users[0]['TGL_PENGAJUAN']; ?>" disabled>
						</div>
					</div>
					<?php if($tk1 != '0') :?>
					<div class="line line-dashed line-lg pull-in"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label">Nama SD/PAKET A</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" data-required="true" value="<?php echo $tk1; ?>" disabled>
						</div>
					</div>							
					<div class="form-group">
						<label class="col-sm-4 control-label">Jumlah legalisir</label>
						<div class="col-sm-3">
							<input type="text" class="form-control" data-required="true" value="<?php if ($lembar_tk1 != '0') echo $lembar_tk1; else echo '' ?>" disabled>
						</div>
						<div class="col-sm-4">
							<a class="btn btn-info" target="_blank" href="<?php echo (!empty($alamat_tk1))?base_url().$alamat_tk1:"javascript:message()";?>"><i class="fa fa-file text"></i><span class="text"> Ijazah</span></a>
						</div>							
					</div>
					<?php endif; ?>
					<?php if($tk2 != '0') :?>
					<div class="line line-dashed line-lg pull-in"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label">Nama SMP/PAKET B</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" data-required="true" value="<?php echo $tk2; ?>" disabled>
						</div>
					</div>												
					<div class="form-group">
						<label class="col-sm-4 control-label">Jumlah legalisir</label>
						<div class="col-sm-3">
							<input type="text" class="form-control" data-required="true" value="<?php if ($lembar_tk2 != '0') echo $lembar_tk2; else echo '' ?>" disabled>
						</div>
						<div class="col-sm-4">
							<a class="btn btn-info" target="_blank" href="<?php echo (!empty($alamat_tk2))?base_url().$alamat_tk2:"javascript:message()";?>"><i class="fa fa-file text"></i><span class="text"> Ijazah</span></a>
						</div>							
					</div>
					<?php endif; ?>
					<?php if($tk3 != '0') :?>
					<div class="line line-dashed line-lg pull-in"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label">Nama SMA/PAKET C</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" data-required="true" value="<?php echo $tk3; ?>" disabled>
						</div>
					</div>												
					<div class="form-group">
						<label class="col-sm-4 control-label">Jumlah legalisir</label>
						<div class="col-sm-3">
							<input type="text" class="form-control" data-required="true" value="<?php if ($lembar_tk3 != '0') echo $lembar_tk3; else echo '' ?>" disabled>
						</div>
						<div class="col-sm-4">
							<a class="btn btn-info" target="_blank" href="<?php echo (!empty($alamat_tk3))?base_url().$alamat_tk3:"javascript:message()";?>"><i class="fa fa-file text"></i><span class="text"> Ijazah</span></a>
						</div>							
					</div>
					<?php endif; ?>
					<div class="line line-dashed line-lg pull-in"></div>					
					<div class="form-group">
						<label class="col-sm-4 control-label">Alasan pengajuan</label>
						<div class="col-sm-7">
							<textarea class="form-control" rows="3" data-minwords="6" data-required="true"  disabled><?php echo $users[0]['ALASAN']; ?></textarea>
						</div>
					</div>
					<div class="line line-dashed line-lg pull-in"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label">Penanda tangan</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" data-required="true" value="<?php if($users[0]['VERIFIKATOR'] == 1) echo 'SEKRETARIS'; else echo 'KEPALA DINAS';?>" disabled>
						</div>
					</div>
					<div class="line line-dashed line-lg pull-in"></div>
					<div class="form-group">
						<label class="col-sm-4 control-label">Status</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" data-required="true" value="<?php echo ($users[0]['STATUS'] == 1) ? ("Belum diproses") : (($users[0]['STATUS'] == 2) ? ("Sedang diproses") : (($users[0]['STATUS'] == 3) ? ("Sudah diverifikasi") : (($users[0]['STATUS'] == 4) ? ("Sudah dicetak") : ("Sudah diambil"))));?>" disabled>
						</div>
					</div>
					<input type="hidden" value="<?php echo $id?>" id="id_pengajuan">
					<div class="form-group">			
						<div class="col-lg-11 control-label">
							<div class="doc-buttons">
								<a href="#" onClick="window.history.back();" class="btn btn-sm btn-info"><i class="fa fa-arrow-circle-left text"></i><span class="text"> Kembali</span></a>
								<a href="javascript:konfirmasi(<?php echo $id?>)" class="btn btn-sm btn-info" <?php echo ($users[0]['STATUS'] > 2) ? ("disabled") : ("");?>><i class="fa fa-thumbs-o-up text"></i><span class="text"> Verifikasi</span></a>
								<a href="<?php echo site_url('admin/adlegalisir/tolak_permohonan/' . $id);?>" class="btn btn-sm btn-info" <?php echo ($users[0]['STATUS'] > 2) ? ("disabled") : ("");?>><i class="fa fa-thumbs-o-down text"></i><span class="text"> Tolak Verifikasi</span></a>
							</div>
						</div>				
					</div>						
				</form>
			</div>
		</section>	
	</div>
</div>
<div style="display:none;">
	<form method="post" class="panel-body" id="pengajuan" enctype="multipart/form-data">
		<?php
			$email 	= '';
			$nama	= '';
			$link	= '';
			$korektor = $users[0]['VERIFIKATOR'];
		
			if($users[0]['STATUS_TK1'] == 'NF' || $users[0]['STATUS_TK2'] == 'NF' || $users[0]['STATUS_TK3'] == 'NF')
			{
				$email 	= 'kabid.dispendik@gmail.com';
				$nama	= 'Kabid';
				$link	= '<a href=\'http://energeek.co.id/PHPMailer_5.2.0/apilegalisir/index.php/sendmail/send_sekretaris?nama='.$users[0]['NAMA_LENGKAP'].'&alamat='.$users[0]['ALAMAT'].'&sd='.$users[0]['TK1'].'&smp='.$users[0]['TK2'].'&sma='.$users[0]['TK3'].'&korektor='.$korektor.'&id='.$id.' \'>Disini</a>';
			}
			else
			{
				$email 	= 'sekretaris.dinas@gmail.com';
				$nama	= 'Sekretaris';
				
				if($korektor == 1)
				{
					$link 	= '<a href=\'http://202.154.13.119/legalisironline/admin/adlegalisir/konf_akhir_sekre?id='.$id.' \'>Disini</a>';
				}
				elseif($korektor == 2)
				{
					$link	= '<a href=\'http://energeek.co.id/PHPMailer_5.2.0/apilegalisir/index.php/sendmail/send_kadin?nama='.$users[0]['NAMA_LENGKAP'].'&alamat='.$users[0]['ALAMAT'].'&sd='.$users[0]['TK1'].'&smp='.$users[0]['TK2'].'&sma='.$users[0]['TK3'].'&korektor='.$korektor.'&id='.$id.' \'>Disini</a>';
				}
			}
			
			$isi = '
				<html>
					<head>
						Pengajuan legalisir online
					</head>
				<body>
					<p>Kepada Yth.</p>
					<p>'.$nama.' Dinas Pendidikan Kota Surabaya</p>
					<p>di Surabaya</p>

					<p>Kami menginformasikan kepada anda mengenai berkas yang berkaitan dengan pengajuan legalisir online yang perlu anda kaji. Berikut data - data mengenai user terkait :</p>

					<p>Nama : '.$users[0]['NAMA_LENGKAP'].' </p>
					<p>Alamat : '.$users[0]['ALAMAT'].'</p>
					<p>Sekolah : '.$users[0]['TK1'].' '.$users[0]['TK2'].' '.$users[0]['TK3'].'</p>

					<p>Bila data - data sudah sesuai dengan permintaaan silahkan klik '.$link.' untuk memberikan approval. Demikian informasi yang dapat kami sampaikan.</p>

					<p>Terima Kasih,</p>
					<p>Admin Legalisir Online Dinas Pendidikan Kota Surabaya</p>
				</body>
				<script>
				function tembusan(){
					alert("Data terkirim");
				}
				</script>
				</html>
			';
		?>
		
		<?php $value = 'Webmaster Legalisir'; ?>
		<input type="hidden" name="From_Name" value="<?php echo $value; ?>">
		<?php $value = 'hello@arfatech.co.id'; ?>
		<input type="hidden" name="From_Email" value="<?php echo $value; ?>">
		<?php $value = $nama; ?>
		<input type="hidden" name="To_Name" value="<?php echo $value; ?>">
		<?php $value = $email; ?>
		<input type="hidden" name="To_Email" value="<?php echo $value; ?>">
		<?php $value = 'Pengajuan Legalisir'; ?>
		<input type="hidden" name="Subject" value="<?php echo $value; ?>">
		<?php $value = $isi ?>
		<input type="hidden" name="Message" value="<?php echo $value; ?>">
	</form>
</div>

<?php }else{ echo $this->load->view("403_page"); }?>

<?php
	$urlajax = '';
	
	if($users[0]['STATUS_TK1'] == 'NF' && $users[0]['STATUS_TK2'] == 'NF' && $users[0]['STATUS_TK3'] == 'NF')
	{
		$urlajax = base_url().'admin/adlegalisir/konfirmasi_permohonan2/'.$id;
	}
	elseif($users[0]['STATUS_TK1'] == 'S' && $users[0]['STATUS_TK2'] == 'S' && $users[0]['STATUS_TK3'] == 'S')
	{
		$urlajax = base_url().'admin/adlegalisir/konfirmasi_permohonan2/'.$id;
	}
	else
	{
		$urlajax = base_url().'admin/adlegalisir/konfirmasi_permohonan/'.$id;
	}
?>
<script>
function message(){
	alert("Belum ada ijazah !");
}
function konfirmasi(id){
	var id_pengajuan = $("#id_pengajuan").val();
	var res	= {
			loader:$('<div />', {class: 'loader'}),
			maincol: $('body')
		}
	$.ajax({
		   type: "POST",
		   data: id_pengajuan,
		   url:"<?php echo $urlajax?>",
		   beforeSend:function(){
			res.maincol.append(res.loader);
		   },
		   success: function(data)
		   {
				if(data == "success"){
					$.ajax({
						type: "POST",
						url: 'http://energeek.co.id/PHPMailer_5.2.0/test_script/index.php',
						data : $("#pengajuan").serialize(),
						async:false,
						success: function(data)
						{
							alert("Data sudah terkirim");
							location.href="<?php echo base_url()?>admin/adlegalisir/j_permohonan/1";
						},
						error: function(data)
						{
							alert("Data sudah terkirim");
							location.href="<?php echo base_url()?>admin/adlegalisir/j_permohonan/1";
						},
						
					});
				}
				else if (data == "pending"){
					alert("Data telah diproses. Menunggu verifikasi oleh verifikator lainnya.");
					location.href="<?php echo base_url()?>admin/adlegalisir/j_permohonan/1";
				}
				else if (data == "error"){
					alert("Gagal");
				}
		   },
		});
}
</script>